using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ImageMap : EntityTypeConfiguration<Image>
    {
        public ImageMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Cust_ID)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.Description)
                .HasMaxLength(100);

            this.Property(t => t.FileName)
                .HasMaxLength(50);

            this.Property(t => t.im_Title)
                .HasMaxLength(50);

            this.Property(t => t.IMG_RecordType)
                .HasMaxLength(30);

            this.Property(t => t.IMG_RecordID)
                .HasMaxLength(30);

            // Table & Column Mappings
            this.ToTable("Images");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Cust_ID).HasColumnName("Cust_ID");
            this.Property(t => t.Category_ID).HasColumnName("Category_ID");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.Thumb).HasColumnName("Thumb");
            this.Property(t => t.Image1).HasColumnName("Image");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.tooth_nb).HasColumnName("tooth_nb");
            this.Property(t => t.FileName).HasColumnName("FileName");
            this.Property(t => t.im_Title).HasColumnName("im_Title");
            this.Property(t => t.im_Note).HasColumnName("im_Note");
            this.Property(t => t.IMG_RecordType).HasColumnName("IMG_RecordType");
            this.Property(t => t.IMG_RecordID).HasColumnName("IMG_RecordID");

            // Relationships
            this.HasRequired(t => t.Cust)
                .WithMany(t => t.Images)
                .HasForeignKey(d => d.Cust_ID);
            this.HasRequired(t => t.ImgCat)
                .WithMany(t => t.Images)
                .HasForeignKey(d => d.Category_ID);

        }
    }
}
